package com.myproject.myspringboot.service;

import com.myproject.myspringboot.mapper.UserMapper;
import com.myproject.myspringboot.pojo.ResponeBean;
import com.myproject.myspringboot.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.EAN;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hushuhua
 * @date 2020/2/20 14:52
 * @discription
 */
@Service
@Slf4j
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public List<User> findUsers() {
        return userMapper.findUsers();
    }

    public ResponeBean addUser(User user) {
        try {
            userMapper.addUser(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("添加完成");
        return new ResponeBean(200,"添加成功！","");
    }

    public ResponeBean updateById(User user) {
        userMapper.updateById(user);
        log.info("更新成功");
        return new ResponeBean(200,"更新成功!","");
    }

    public ResponeBean delById(String id) {
        userMapper.delById(id);
        log.info("删除成功！");
        return new ResponeBean(200,"删除成功！","");
    }
}
